<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../static/weixinKp/css/mui.min.css">
    <link rel="stylesheet" href="../static/weixinKp/css/main.css">
    <title>查询结果</title>
    <style media="screen">
    </style>
</head>

<body>
    <div class="wrap">

    </div>
    <script src="../static/weixinKp/js/jquery-3.2.1.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="../static/weixinKp/js/path.js"></script>
    <script src="../static/weixinKp/js/mui.min.js"></script>
    <script type="text/javascript">
        var userId = document.cookie.split(";")[1].split("=")[1];
        var custOrBuyerName = decodeURI(getQueryString('custOrBuyerName'));
        var state = decodeURI(getQueryString('state'));
        var date = decodeURI(getQueryString('date'));
        $(document).ready(function() {
            $.ajax({
                url: path + '/app/invoiceRecord/list',
                type: 'post',
                headers: {
                    userId: userId
                },
                xhrFields: {
                    withCredentials: true
                },
                dataType: 'json',
                data: {
                    custOrBuyerName: custOrBuyerName,
                    state: state,
                    period: date
                },
                success: (data) => {
                    var html = '';
                    if (data.data.length > 0) {
                        for (var i = 0; i < data.data.length; i++) {
                            html += '<div class="resultSelect">';
                            html += '<div class="resulttop">';
                            html += '<span class="result_money">￥' + data.data[i].invoicetotalmoney + '</span>';
                            if (data.data[i].state == 1) {
                                html += '<span class="result_time" style="color:#f75607;">待处理</span>';
                            } else if (data.data[i].state == 2) {
                                html += '<span class="result_time" style="color:#f75607;">处理中</span>';
                            } else if (data.data[i].state == 3) {
                                html += '<span class="result_time" style="color:#f75607;">已完成</span>';
                            } else if (data.data[i].state == 4) {
                                html += '<span class="result_time " style="color:#f75607;">已取消</span>';
                            }
                            html += '</div>';
                            html += ' <p class="resultP">委方：' + data.data[i].conCustomername + '</p>';
                            html += ' <p class="resultP">购方：' + data.data[i].buyerName + '</p>';
                            html += ' <p class="resultP" style="border-bottom:1px dotted #c0c0c0;">提交时间：' + data.data[i].createtime + '</p>';
                            html += '<div class="resulttop">';
                            html += '<input type="hidden" value="' + data.data[i].invoiceRecordId +
                                '"/><span class="result_time more" style="color:#333"><img src="./images/company_search.png" alt="" class="icon-search"/>查看详情</span>';
                            if (data.data[i].state == 1) {
                                html += '<span class="result_cancel cancel_invice" style="color:#333"><img src="./images/express_delete.png" alt="" class="icon-del"/>取消开票</span>';
                            }
                            html += '</div>';
                            html += '</div>';
                        }
                    } else {
                        html += '<img src="./images/result_oops.png" alt="" class="result_oops"/>';
                        html += '<p class="result_note">暂无记录！</p>';
                    }
                    $(".wrap").append(html);
                },
                error: (err) => {
                    mui.alert(err.message)
                }
            })
        })
        // 跳转到详情
        $(document).on('touchstart', '.more', function() {
            var invoiceRecordId = $(this).parent().find('input').val();
            var type = decodeURI(getQueryString('type'));
            var state = decodeURI(getQueryString('state'));
            window.location.href = './DetailInvoice.html?invoiceRecordId=' + invoiceRecordId + '&type=' + type + '&state=' + state;
        })
        // 取消开票
        $(document).on('touchstart', '.cancel_invice', function() {
            var invoiceRecordId = $(this).parent().find('input').val();
            $.ajax({
                url: path + '/app/invoiceRecord/cancel',
                dataType: 'json',
                type: 'post',
                headers: {
                    userId: userId
                },
                xhrFields: {
                    withCredentials: true
                },
                data: {
                    invoiceRecordId: invoiceRecordId
                },
                success: (data) => {
                    console.log(data);
                    if (data.success = 1) {
                        mui.alert(data.message, function() {
                            window.location.replace('./user.html');
                        });
                    }
                },
                error: (err) => {
                    mui.alert(err.message)
                }
            })
        })
    </script>
</body>

</html>
